﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCA.Community.DAL.Interfaces;
using LCA.Community.DAL.Model;

namespace LCA.Community.DAL
{
    /// <summary>
    /// The repository implementation for avatars manipulation.
    /// </summary>
    public class AvatarsRepository : IAvatarsRepository
    {
        #region Fields
        private IStorageServiceContext<Avatar> _storageServiceContext; 
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="AvatarsRepository"/> class.
        /// </summary>
        /// <param name="storageServiceContext">The storage service context.</param>
        public AvatarsRepository(IStorageServiceContext<Avatar> storageServiceContext)
        {
            _storageServiceContext = storageServiceContext;
        } 
        #endregion

        #region Methods
        /// <summary>
        /// Adds the specified avatar.
        /// </summary>
        /// <param name="avatar">The avatar.</param>
        public void Add(Avatar avatar)
        {
            _storageServiceContext.Add(avatar);
        }

        /// <summary>
        /// Gets the URL of the specified avatar.
        /// </summary>
        /// <param name="avatar">Avatar.</param>
        /// <returns>The url of the avatar.</returns>
        public Uri GetUrl(Avatar avatar)
        {
            return _storageServiceContext.GetUrl(avatar);
        }

        /// <summary>
        /// Gets the URL of the specified avatar.
        /// </summary>
        /// <param name="name">The name of the entity.</param>
        /// <param name="container">The container.</param>
        /// <returns>The url of the avatar. </returns>
        public Uri GetUrl(string name, string container)
        {
            return new Uri(String.Format("{0}/{1}/{2}", _storageServiceContext.BaseURL, container, name));
        }

        /// <summary>
        /// Check if the entity exists.
        /// </summary>
        /// <param name="avatar">The avatar.</param>
        /// <returns></returns>
        public bool Exists(Avatar avatar)
        {
            return _storageServiceContext.Exist(avatar);
        }

        /// <summary>
        /// Deletes the specified avatar.
        /// </summary>
        /// <param name="avatar">The avatar.</param>
        public void Delete(Avatar avatar)
        {
            _storageServiceContext.Delete(avatar);
        }
        #endregion
    }
}
